package cn.piaoyi.service.imp;

import java.util.*;

import org.apache.commons.logging.*;
import cn.piaoyi.bean.Price;
import cn.piaoyi.dao.PriceDAO;
import cn.piaoyi.exception.PiaoyiException;
import cn.piaoyi.service.PriceService;


public class PriceServiceImp implements PriceService {

	private static final Log logger = LogFactory.getLog(PriceServiceImp.class);
	
	private PriceDAO priceDAO;

	public PriceDAO getPriceDAO() {
		return priceDAO;
	}

	public void setPriceDAO(PriceDAO priceDAO) {
		this.priceDAO = priceDAO;
	}

	/**
	 * 保存Price对象
	 * 
	 * @param price
	 * 			Price对象
	 * @return Price
	 * 			Price对象
	 */
	public Price createPrice(Price price) throws PiaoyiException{
		try {
			price = this.getPriceDAO().savePrice(price);
			return price;
		} catch (Exception e) {
			logger.error(e);
			throw new PiaoyiException(e);
		}
	}

	/**
	 * 保存Price对象
	 * 
	 * @param price
	 * 			Price对象
	 * @return Price
	 * 			Price对象
	 */
	public Price updatePrice(Price price) throws PiaoyiException{
		try {
			price = this.getPriceDAO().updatePrice(price);
			return price;
		} catch (Exception e) {
			logger.error(e);
			throw new PiaoyiException(e);
		}
	}
	
	/**
	 * 根据主键ID获取Price对象
	 * 
	 * @param id
	 * 			主键ID
	 * @return Price
	 * 			Price对象
	 */
	public Price findPriceById(long id){
		return this.getPriceDAO().findPriceById(id);
	}
	
	/**
	 * 获取Price列表
	 * 
	 * @param goodsId
	 * 			long
	 * @param dailyId
	 * 			long
	 * @param orderby
	 *            String
	 * @param ascOrDesc
	 *            int
	 * @return List
	 * 			Price对象列表
	 */
	public List findPrices(long goodsId,long dailyId,String orderby, int ascOrDesc){
		return this.getPriceDAO().findPrices(goodsId,dailyId, orderby, ascOrDesc);
	}
	
	/**
	 * 删除Price对象
	 */
	public void removePriceById(long id){
		this.getPriceDAO().removePriceById(id);
	}
}
